/*
 * Localidad.java
 *
 * Created on 3 de abril de 2007, 17:30
 */

package despachador.pagina;

import excepciones.AvwException;

import gestores.pagina.GestorCliente;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.*;
import javax.servlet.http.*;
/**
 *
 * @author Administrador
 * @version
 */
public class Localidad extends HttpServlet {
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        ArrayList<HashMap> localidades = new ArrayList<HashMap>();
        ArrayList<HashMap> paises = GestorCliente.listarPaises();
        ArrayList<HashMap> provincias = GestorCliente.listarProvincias();
        request.setAttribute("paises", paises);
        request.setAttribute("provincias", provincias);
        String pais =  request.getParameter("pais");
        String provincia = request.getParameter("provincia");
        if( provincia != null){localidades = GestorCliente.listarLocalidades(provincia); }
        request.setAttribute("localidades", localidades);
        String url = "/micrositios/" + (String) request.getAttribute("nomMicro");

        // Especificamos que pagina se coloca en cada parte del layout
        request.setAttribute("1", url + "/encabezado.jsp");
        request.setAttribute("2", url + "/destacado.jsp");
        request.setAttribute("3", url + "/buscador.jsp");
        request.setAttribute("4", "/vistas/pagina/menuizq.jsp");
        request.setAttribute("5", url + "/bannerizq.jsp");

        request.setAttribute("6", "/vistas/pagina/registrar.jsp");

        request.setAttribute("7", "/vistas/pagina/visitados.jsp");
        request.setAttribute("8", "/vistas/pagina/login.jsp");
        request.setAttribute("9", "/vistas/pagina/rss.jsp");
        request.setAttribute("11", "/vistas/pagina/marcas.jsp");
        request.setAttribute("10", url + "/pie.jsp");
        
        dispatch(request, response, "/compositor/pagina/nuevecuerpos.jsp");
    }
    
    
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
     /**
     * dispatcher method
     */
    protected void dispatch(HttpServletRequest request,
            HttpServletResponse response, String page)
            throws javax.servlet.ServletException,
            java.io.IOException {
        RequestDispatcher dispatcher =
                getServletContext().
                getRequestDispatcher(page);
        dispatcher.forward(request, response);
    }
}
